home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / nn.zip / DB.H < prev    next >
C/C++ Source or Header  |  1989-06-28  |  3KB  |  102 lines

  1. /*
  2.  
  3.  * DATABASE ORGANIZATION:
  4.  *
  5.  *    The central nn information is contained in following files:
  6.  *        DB_DIRECTORY/MASTER
  7.  *        DB_DIRECTORY/GROUPS
  8.  *        DB_DIRECTORY/DATA/nnn.x
  9.  *        DB_DIRECTORY/DATA/nnn.d
  10.  *
  11.  *     The MASTER file consists of a header and one entry for each news
  12.  *    group.  The sequence of the group headers defines the group
  13.  *    number associated with the group.
  14.  *
  15.  *     The GROUPS file contains the names of the news groups; the names
  16.  *    occur in the same sequence as in the MASTER file.
  17.  *
  18.  *    For each news group, the DATA directory contains two files whose
  19.  *    name is constructed from the group number 'nnn':
  20.  *
  21.  *        nnn.x    Index file
  22.  *        nnn.d    Data file
  23.  *
  24.  *    The index file provides a a mapping from article numbers to offsets
  25.  *    in the data file.
  26.  *
  27.  *    The data file contains the actual header data.  Each article is
  28.  *    represented by a Header, an array of Cross Postings, and the
  29.  *    strings representing the sender name and the article subject:
  30.  *
  31.  *        header
  32.  *        group_number 1 [ if cross posted ]
  33.  *        group_number 2
  34.  *        ...
  35.  *        sender name (null terminated) [if sender_length > 0]
  36.  *        subject (null terminated) [if subject_length > 0]    
  37.  *
  38.  *    For a digest, cross posted groups are only specified for first 
  39.  *    the entry.
  40.  *
  41.  *    The format of the MASTER file is specifed in the data.h
  42.  *    file.  The format of the index and data files are specified below. 
  43.  *
  44.  *    Unless NETWORK_DATABASE is defined, the database will
  45.  *    will contain machine dependent binary data.
  46.  */
  47.  
  48. typedef struct {
  49.     off_t        data_offset;
  50. } index_entry;
  51.  
  52. typedef struct {
  53.     article_number    dh_number;
  54.  
  55.     time_stamp    dh_date; /* encoded Date: filed (not a time_t value!!) */
  56.         
  57.     off_t    dh_hpos; /* absolute offset for first byte of header */
  58.     off_t    dh_lpos; /* absolute offset for last byte of article */
  59.     int16    dh_fpos; /* relative offset for first byte in article text */
  60.     
  61.     int16    dh_lines;
  62.     int8    dh_replies;
  63.     
  64.     int8    dh_cross_postings;
  65.     int8    dh_subject_length;
  66.     int8    dh_sender_length;
  67. } data_header;
  68.  
  69. /*
  70.  *     The article_number is negative for digest article header and 
  71.  *     zero for following sub articles.
  72.  */
  73.  
  74. article_number    current_digest_article;
  75.  
  76. #define    IS_DIGEST_HEADER(e1) \
  77.     ((e1).dh_number < 0 && (current_digest_article = -((e1).dh_number)))
  78. #define    IS_SUB_DIGEST(e1) \
  79.     (((e1).dh_number) == 0)
  80. #define    ARTICLE_NUMBER(e1) \
  81.     (((e1).dh_number <= 0) ? current_digest_article : ((e1).dh_number))
  82.  
  83.  
  84.  
  85. #ifdef NETWORK_DATABASE
  86. typedef int32 cross_post_number;
  87. #else
  88. typedef group_number cross_post_number;
  89. #endif
  90.  
  91.  
  92. /* open database files */
  93.  
  94. FILE *open_groups(), *open_data_file();
  95.  
  96. /* data access */
  97.  
  98. off_t get_index_offset(), get_data_offset();
  99.  
  100.  
  101.  
  102.